/*
 * Licensed to the OpenAirInterface (OAI) Software Alliance under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The OpenAirInterface Software Alliance licenses this file to You under
 * the OAI Public License, Version 1.1  (the "License"); you may not use this
 * file except in compliance with the License. You may obtain a copy of the
 * License at
 *
 *      http://www.openairinterface.org/?page_id=698
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *-------------------------------------------------------------------------------
 * For more information about the OpenAirInterface (OAI) Software Alliance:
 *      contact@openairinterface.org
 */
/**
 * Nudm_UECM
 * Nudm Context Management Service. � 2020, 3GPP Organizational Partners (ARIB,
 * ATIS, CCSA, ETSI, TSDSI, TTA, TTC). All rights reserved.
 *
 * The version of the OpenAPI document: 1.1.2
 *
 *
 * NOTE: This class is auto generated by OpenAPI Generator
 * (https://openapi-generator.tech). https://openapi-generator.tech Do not edit
 * the class manually.
 */
/*
 * Helpers.h
 *
 * This is the helper class for models and primitives
 */

#ifndef Helpers_H_
#define Helpers_H_

#include <ctime>
#include <map>
#include <sstream>
#include <string>
#include <vector>
#include "Snssai.h"
#include "PlmnId.h"
using namespace oai::udm::model;

namespace oai {
namespace udm {
namespace helpers {

std::string toStringValue(const std::string& value);
std::string toStringValue(const int32_t& value);
std::string toStringValue(const int64_t& value);
std::string toStringValue(const bool& value);
std::string toStringValue(const float& value);
std::string toStringValue(const double& value);

bool fromStringValue(const std::string& inStr, std::string& value);
bool fromStringValue(const std::string& inStr, int32_t& value);
bool fromStringValue(const std::string& inStr, int64_t& value);
bool fromStringValue(const std::string& inStr, bool& value);
bool fromStringValue(const std::string& inStr, float& value);
bool fromStringValue(const std::string& inStr, double& value);

bool fromStringValue(const std::string& inStr, oai::udm::model::PlmnId& value);
bool fromStringValue(const std::string& inStr, oai::udm::model::Snssai& value);

template<typename T>
bool fromStringValue(
    const std::vector<std::string>& inStr, std::vector<T>& value) {
  try {
    for (auto& item : inStr) {
      T itemValue;
      if (fromStringValue(item, itemValue)) {
        value.push_back(itemValue);
      }
    }
  } catch (...) {
    return false;
  }
  return value.size() > 0;
}
template<typename T>
bool fromStringValue(
    const std::string& inStr, std::vector<T>& value, char separator = ',') {
  std::vector<std::string> inStrings;
  std::istringstream f(inStr);
  std::string s;
  while (std::getline(f, s, separator)) {
    inStrings.push_back(s);
  }
  return fromStringValue(inStrings, value);
}

}  // namespace helpers
}  // namespace udm
}  // namespace oai

#endif  // Helpers_H_
